* 8_AdditionalStatewideElectionsRegressions
** Goal: regressions that examine additional statewide elections (att gen, lt gub, sec state)
** Beatrice Lee
** Date Created: 2024-06-19
** Last Updated: 2024-07-09 // bal

cd "$Data/Processing"
*use state_elections_panel_ll_20240618, clear
use additional_statewide_elect_20240709, clear
**************************************** CODING **************************************************

gen duringpandemic = 0
replace duringpandemic = 1 if year >= 2020 & year <= 2023

gen gub_ind = 0
replace gub_ind = 1 if office == "gub"

encode office, gen(office_num)

*************************************** DEP VAR MEANS ********************************************
sum margin_ctrl_gub_pty margin_inc_pty if year >= 2020
sum margin_ctrl_gub_pty margin_inc_pty if ((year >= 2020 & year <= 2022 ) & is_separate_from_gub != "Yes")

sum margin_ctrl_gub_pty margin_inc_pty if year > 2012
sum margin_ctrl_gub_pty margin_inc_pty if ((year > 2012) & is_separate_from_gub != "Yes")

*1) using pandemic sample

eststo clear

*** Did Aid Impact Other Statewide Elections? 

*********************** OUTCOME = GUB PARTY INC

**** No Controls
eststo: ivregress 2sls margin_ctrl_gub_pty (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** + Lagged Dep Var
eststo: ivregress 2sls margin_ctrl_gub_pty margin_ctrl_gub_pty_prev (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** No Controls, Drop same-ticket lt gubs
eststo: ivregress 2sls margin_ctrl_gub_pty (total_1k_muni_aid_per_resident = reps_per_million ) if ((year >= 2020 & year <= 2022 ) & is_separate_from_gub != "Yes"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** + Lagged Dep Var, Drop same-ticket lt gubs
eststo: ivregress 2sls margin_ctrl_gub_pty margin_ctrl_gub_pty_prev (total_1k_muni_aid_per_resident = reps_per_million ) if ((year >= 2020 & year <= 2022 ) & is_separate_from_gub != "Yes"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

*********************** OUTCOME = POSITION PARTY INC

**** No Controls
eststo: ivregress 2sls margin_inc_pty (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** + Lagged Dep Var
eststo: ivregress 2sls margin_inc_pty margin_inc_pty_prev (total_1k_muni_aid_per_resident = reps_per_million ) if (year >= 2020 & year <= 2022), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** No Controls, Drop same-ticket lt gubs
eststo: ivregress 2sls margin_inc_pty (total_1k_muni_aid_per_resident = reps_per_million ) if ((year >= 2020 & year <= 2022 ) & is_separate_from_gub != "Yes"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** + Lagged Dep Var, Drop same-ticket lt gubs
eststo: ivregress 2sls margin_inc_pty margin_inc_pty_prev (total_1k_muni_aid_per_resident = reps_per_million ) if ((year >= 2020 & year <= 2022 ) & is_separate_from_gub != "Yes"), vce(cluster state) first
estat firststage

mat fstat = r(singleresults)
estadd scalar fs = fstat[1,4]

**** Export Table to Latex
cd "$Results"
esttab using "additional_statewide_elections_2sls_20240709.tex", replace /// Replace file if it already exists
 collabels("\multicolumn{1}{c}{1l}" "\multicolumn{1}{c}{l2}" "\multicolumn{1}{c}{l3}" "\multicolumn{1}{c}{l4}" "\multicolumn{1}{c}{l5}" "\multicolumn{1}{c}{l6}" "\multicolumn{1}{c}{l7}" "\multicolumn{1}{c}{l8}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 fs, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" )  labels(`"Observations"' `"\(R^{2}\)"' `"\(F\)"')) drop(_cons) ///
 booktabs ///
 title("Additional Statewide Elections 2sls") ///
 addnotes("Note: TKTKTKTK")

*2) using panel

eststo clear

************* MoV Gub Control - all elections
*** Col1
eststo: reg margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012) , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

/*
*** Col2
reg margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if (year > 2012) , vce(cluster state)
outreg2 using "$voter_turnout_panel", append ctitle(MoV Gub Party)
*/

/*
*** Col3
eststo: reg margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012) , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "No"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
*** Col4: vote share during the pandemic by including state and year fixed effects
eststo: reghdfe margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012) , vce(cluster state) a(sfips year)
outreg2 using "$voter_turnout_panel", append ctitle(MoV Gub Party)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

** Col5: Adds Office Fixed Effects
eststo: reghdfe margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012), vce(cluster state) a(sfips office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"
*/

** Col6: Adds Office by State Fixed Effects
eststo: reghdfe margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012) , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

************* MoV Gub Control - exclude same-ballot
*** Col1
eststo: reg margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

/*
*** Col2
reg margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state)
outreg2 using "$voter_turnout_panel", append ctitle(MoV Gub Party)
*/

/*
*** Col3
eststo: reg margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "No"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
*** Col4: vote share during the pandemic by including state and year fixed effects
eststo: reghdfe margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state) a(sfips year)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

** Col5: Adds Office Fixed Effects
eststo: reghdfe margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes"), vce(cluster state) a(sfips office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"
*/

** Col6: Adds Office by State Fixed Effects
eststo: reghdfe margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

************* MoV Inc Control - all elections
*** Col1
eststo: reg margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012) , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

/*
*** Col2
reg margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if (year > 2012) , vce(cluster state)
outreg2 using "$voter_turnout_panel", append ctitle(MoV Inc Party)
*/

/*
*** Col3
eststo: reg margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012) , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "No"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
*** Col4: vote share during the pandemic by including state and year fixed effects
eststo: reghdfe margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012) , vce(cluster state) a(sfips year)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

** Col5: Adds Office Fixed Effects
eststo: reghdfe margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012), vce(cluster state) a(sfips office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"
*/

** Col6: Adds Office by State Fixed Effects
eststo: reghdfe margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012) , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"

************* MoV Gub Control - exclude same-ballot
*** Col1
eststo: reg margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "No"
estadd local state_fe "No"
estadd local norm_vote_year_fe "No"
estadd local office_state_fe "No"

/*
*** Col2
reg margin_ctrl_gub_pty margin_ctrl_gub_pty_prev c.reps_per_million##i.duringpandemic norm_vote_top2_share_sd if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state)
outreg2 using "$voter_turnout_panel", append ctitle(MoV Inc Party)
*/

/*
*** Col3
eststo: reg margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "No"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

*** Panel regressions estimating the differential relationship between reps per million and the incumbent
*** Col4: vote share during the pandemic by including state and year fixed effects
eststo: reghdfe margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state) a(sfips year)

estadd local office_fe "No"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"

** Col5: Adds Office Fixed Effects
eststo: reghdfe margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes"), vce(cluster state) a(sfips office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "No"
*/

** Col6: Adds Office by State Fixed Effects
eststo: reghdfe margin_inc_pty margin_inc_pty_prev c.reps_per_million##i.duringpandemic if (year > 2012 & is_separate_from_gub != "Yes") , vce(cluster state) a(sfips#office_num year)

estadd local office_fe "Yes"
estadd local year_fe "Yes"
estadd local state_fe "Yes"
estadd local norm_vote_year_fe "Yes"
estadd local office_state_fe "Yes"


****** Export Table to Latex
cd "$Results/"
esttab using "additional_statewide_elections_panel_20240709.tex", replace ///
 collabels("\multicolumn{1}{c}{col1}" "\multicolumn{1}{c}{col2}" "\multicolumn{1}{c}{col3}" "\multicolumn{1}{c}{col4}" "\multicolumn{1}{c}{col5}" "\multicolumn{1}{c}{col6}" "\multicolumn{1}{c}{col7}" "\multicolumn{1}{c}{col8}") ///
 b(3) se(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01) ///
 stats(N r2 office_fe year_fe state_fe norm_vote_year_fe office_state_fe, fmt(0 3) layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")  labels(`"Observations"' `"\(R^{2}\)"' `"Office FE"' `"Year FE"' `"State FE"' `"Normal Vote x Year FE"' `"Office x State FE"')) drop(_cons) ///
 booktabs /// 
 title("Additional Statewide Elections panel") ///
 addnotes("Note: TKTKTKTK")
